package logic

import (
	"context"
	"rental-system/models/mysql"

	"rental-system/rentalrpc/internal/svc"
	"rental-system/rentalrpc/rentalrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowRentalLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowRentalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowRentalLogic {
	return &ShowRentalLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowRentalLogic) ShowRental(in *rentalrpc.ShowRentalRequest) (*rentalrpc.ShowRentalResponse, error) {
	// todo: add your logic here and delete this line

	var rental mysql.Rental
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&rental)

	return &rentalrpc.ShowRentalResponse{
		Title:   rental.Title,
		Content: rental.Content,
		Price:   float32(rental.Price),
		Address: rental.Address,
	}, nil
}
